#!/usr/bin/python
import os
from dcinstall import setup_py, debian, AbstractPackageInfo
from dcinstall.version import get_revisions, get_changelog_core, save_last_revision

class build(AbstractPackageInfo.build):
    sources_dir = os.path.realpath(os.path.dirname(__file__))
    build_dir = sources_dir
    result_dir = sources_dir + '/dist'

last_revision, cur_revision = get_revisions(build)

class info(AbstractPackageInfo):
    build = build
    version = '1.1-SVN%d' % cur_revision
    changelog_core = get_changelog_core(last_revision, cur_revision)
    name = 'currencies'
    deb_package_name = 'foreignsites-currencies'
    maintainer = 'Maxim Oransky'
    maintainer_email = 'maxim.oransky@gmail.com'
    description = 'Library for work with currencies (load rates)'
    url = 'http://code.google.com/p/foreignsites/'
    deb_depends = [
        'python (>= 2.4)',
    ]
    license = 'GNU Lesser General Public License'


###################
# 1. Classic setup.py installer
setup_py.create(info, skipfiles='.*\.pyc|.*\.pyo|\.svn|\.sqlite')
os.system('python setup.py sdist --formats=gztar')
setup_py.clean()

###################
# 2. Debian package
debian.build_package(
    info,
    ['dist/%s-%s.tar.gz' % (info.name, info.version)],
    custom_deb_templates = {
        'postinst': '%s/postinst.template' % build.build_dir,
    },
)

os.system('mv %s*deb %s' % (info.deb_package_name, build.result_dir))

# on sucess save mark current revision as "last builded"
save_last_revision(build, cur_revision)